<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE xsl:stylesheet SYSTEM "lang://comments">

<xsl:stylesheet
	version="1.0"
	xmlns:php="http://php.net/xsl"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
		
	<xsl:include href="../main.xsl" />
	<xsl:include href="../menu.xsl" />
	<xsl:include href="../common/navigation.xsl" />

	<xsl:template match="/data">
		<html>
		
		<head>
			<title>
				<xsl:value-of select="$pageTitle" />
			</title>
			<xsl:call-template name="meta-head" />
			<link rel="stylesheet" href="{$baseURI}/css/user-comments.css" type="text/css" media="all" />
		</head>
		<body>
			
			<xsl:call-template name="top-userbar" />

			<div id="header">
				<xsl:call-template name="logo" />

				<xsl:call-template name="menu" />
			</div>

			<div id="blocks">				
				<div id="blocks_inner">
					<xsl:call-template name="default-blocks-top" />
				</div>
			</div>

			<div id="content">
				<div id="content_inner">
					<xsl:apply-templates select="response" />
				</div>
			</div>

			<xsl:call-template name="footer" />
		</body>
		</html>
	</xsl:template>
	
	
	
	<!-- RESPONSE -->
	<xsl:template match="response">
		<xsl:apply-templates select="document(concat('xobject://user/', @user-id))/data/object[@type='user']" mode="user-comments-bar" />
		
		<xsl:if test="count (object) = 0">
			<p>Этот пользователь не оставил ни одного комментария</p>
		</xsl:if>
		
		<xsl:if test="count (object) != 0">
			<div id="user_comments">
				<xsl:apply-templates select="object" />
			</div>
		</xsl:if>
		
		<xsl:apply-templates select="pages" mode="pages-navigation">
			<xsl:with-param name="href">
				<xsl:value-of select="concat('/comments/user/', @user-login)" />
			</xsl:with-param>
		</xsl:apply-templates>
	</xsl:template>
	
	<xsl:template match="object[@type-name='article' or @type-name='link']">
		<xsl:param name="publication" select="document(concat('xobject://', property[@name='type_id']/value, '/', property[@name='object_id']/value))/data/object" />
		<xsl:param name="objectLink" select="concat($baseURI, '/post/', $publication/@type, '/', $publication/@id)" />
		<xsl:param name="rating" select="number(property[@name='rating']/value)" />
		
		<div class="comment">
			<xsl:if test="property[@name='deleted']/value = '1'">
				<div class="comment_deleted">&labelDeleted;</div>
			</xsl:if>
			
			<xsl:if test="property[@name='deleted']/value = '0'">
				<div class="header">
					<span class="date">
						<xsl:value-of select="property[@name='pubdate']/value" />
					</span>
					
					<xsl:choose>
						<xsl:when test="@type-name = 'link'">
							<xsl:text> к ссылке «</xsl:text>
						</xsl:when>
						<xsl:otherwise>
							<xsl:text> к публикаци «</xsl:text>
						</xsl:otherwise>
					</xsl:choose>
					
					
					<a href="{$objectLink}">
						<xsl:value-of select="$publication/property[@name='title']/value" disable-output-escaping="yes" />
					</a>
					
					<xsl:text>» </xsl:text>
					
					<a class="link" href="{$objectLink}#comment{@id}" title="&labelLink;">#</a>
					
					<span>
						<xsl:attribute name="class">
							<xsl:choose>
								<xsl:when test="$rating &gt; 0">
									<xsl:text>rating good</xsl:text>
								</xsl:when>
								<xsl:when test="$rating &lt; 0">
									<xsl:text>rating bad</xsl:text>
								</xsl:when>
								<xsl:otherwise>
									<xsl:text>rating</xsl:text>
								</xsl:otherwise>
							</xsl:choose>
							
						</xsl:attribute>
						
						<xsl:if test="$rating &gt; 0">
							<xsl:text>+</xsl:text>
						</xsl:if>
						<xsl:value-of select="property[@name='rating']/value" />
					</span>
				</div>
				<div class="body">
					<xsl:value-of select="property[@name='text']/value" disable-output-escaping="yes" />
				</div>
			</xsl:if>
		</div>
	</xsl:template>
	
	<xsl:template match="object[@type-name='photo']">
		<xsl:param name="photo" select="document(concat('xobject://', property[@name='type_id']/value, '/', property[@name='object_id']/value))/data/object" />
		<xsl:param name="objectLink" select="concat($baseURI, '/photo/', $photo/@id)" />
		<xsl:param name="rating" select="number(property[@name='rating']/value)" />
		
		<div class="comment">
			<xsl:if test="property[@name='deleted']/value = '1'">
				<div class="comment_deleted">&labelDeleted;</div>
			</xsl:if>
			
			<xsl:if test="property[@name='deleted']/value = '0'">			
				<div class="header">
					<span class="date">
						<xsl:value-of select="property[@name='pubdate']/value" />
					</span>
					
					<xsl:text> к фотографии «</xsl:text>
					
					<a href="{$objectLink}">
						<xsl:value-of select="$photo/property[@name='title']/value" disable-output-escaping="yes" />
					</a>
					
					<xsl:text>» </xsl:text>
					
					<a class="link" href="{$objectLink}#comment{@id}" title="&labelLink;">#</a>
					
					<span>
						<xsl:attribute name="class">
							<xsl:choose>
								<xsl:when test="$rating &gt; 0">
									<xsl:text>rating good</xsl:text>
								</xsl:when>
								<xsl:when test="$rating &lt; 0">
									<xsl:text>rating bad</xsl:text>
								</xsl:when>
								<xsl:otherwise>
									<xsl:text>rating</xsl:text>
								</xsl:otherwise>
							</xsl:choose>
							
						</xsl:attribute>
						
						<xsl:if test="$rating &gt; 0">
							<xsl:text>+</xsl:text>
						</xsl:if>
						<xsl:value-of select="property[@name='rating']/value" />
					</span>
				</div>
				<div class="body">
					<xsl:value-of select="property[@name='text']/value" disable-output-escaping="yes" />
				</div>
			</xsl:if>
		</div>
	</xsl:template>
	
	<xsl:template match="object[@type='user']" mode="user-comments-bar">
		<xsl:param name="userLogin" select="property[@name='login']/value" />
		
		<div id="comments_owner_bar">
			<div id="owner_avatar">
				<a href="{$baseURI}/user/{$userLogin}">
					<img>
						<xsl:attribute name="src">
							<xsl:if test="property[@name='avatar']/value = ''">
								<xsl:value-of select="concat ($baseURI, '/images/default-avatar.png')" />
							</xsl:if>
							<xsl:if test="property[@name='avatar']/value != ''">
								<xsl:value-of select="concat ($baseURI, '/thumb_50_50', property[@name='avatar']/value)" />
							</xsl:if>						
						</xsl:attribute>
						<xsl:attribute name="alt">
							<xsl:value-of select="property[@name='name']/value" />
						</xsl:attribute>
					</img>
				</a>
			</div>
			<div id="owner_info">
				<h3 id="owner_name">
					<xsl:text>Комментарии пользователя </xsl:text>
					<a href="{$baseURI}/user/{$userLogin}">
						<xsl:value-of select="property[@name='name']/value" />
					</a>
				</h3>
				<div>
					<a href="{$baseURI}/user/{$userLogin}">&labelUserProfile;</a>
					<a href="{$baseURI}/blogs/user/{$userLogin}">&labelBlog;</a>
					<a href="{$baseURI}/photos/user/{$userLogin}">&labelUserPhotos;</a>
					<a href="{$baseURI}/comments/user/{$userLogin}" class="selected">&labelUserComments;</a>
				</div>
			</div>
		</div>
	</xsl:template>
	
</xsl:stylesheet>